import React, { useEffect, useState } from 'react'
import request from '../../utils/index'
import { Table, Button } from 'antd'
import { useNavigate } from 'react-router-dom'
type Props = {}

const Index = (props: Props) => {
	const navigate = useNavigate()
	const [list, setList] = useState([])

	const getList = async () => {
		const resp = await request({ url: '/api/list', method: 'post' })
		setList(resp.data.data)
	}

	const columns = [{
		title: '标题',
		dataIndex: 'title'
	}, {
		title: '单价',
		dataIndex: 'price'
	},{
		title: '描述',
		dataIndex: 'desc'
	},{
		title: '操作',
		render(row: any) {
			return (
				<div>
					<Button onClick={ () => { navigate('/detail/' + row.key)  } }>查看</Button>
					<Button>编辑</Button>
					<Button>删除</Button>
				</div>
			)
		}
	}]

	useEffect(() => {
		getList()
	}, [])

	return (
		<div>
			<Table dataSource={list} columns={columns}></Table>
		</div>
	)
}

export default Index